package lagou.util;
import javax.swing.*;
import java.util.Scanner;

public class Playgame {

    int[][] arr = new int[16][16];
    public int x;
    public int y;

    //绘制棋盘
    public void draw() {
        System.out.print(" ");
        for (int i = 0; i < 16; i++) {
            System.out.print(" ");
            System.out.printf("%x", i);
        }
        System.out.println();
        for (int i = 0; i < 16; i++) {
            System.out.printf("%x", i);
            for (int j = 0; j < 16; j++) {
                if (arr[i][j] == 0)
                    System.out.print(" +");
                else if (arr[i][j] == 1)
                    System.out.print(" @");   //用@代表黑棋
                else
                    System.out.print(" #");   //用#代表白棋
            }
            System.out.println();
        }
    }

    //提醒黑方白方下棋
    public void notice(int i) {
        Scanner sc = new Scanner(System.in);
        if ((i % 2) == 0) {
            System.out.println("请白方下棋：");
            this.x=sc.nextInt();
            this.y=sc.nextInt();
            if(arr[this.x][this.y]==0)
                arr[this.x][this.y]=2;
            else
                System.out.println("该位置已有棋子！");
        }
        else {
            System.out.println("请黑方下棋：");
            this.x=sc.nextInt();
            this.y=sc.nextInt();
            if(arr[this.x][this.y]==0)
                arr[this.x][this.y]=1;
            else
                System.out.println("该位置已有棋子！");
        }
    }

    //判断是否获胜
    public void judge(int x, int y,int s) {
        this.x=x;
        this.y=y;
        for (int i = 1; i < 2; i++) {
            int a=0;
            int b=0,c=0,d=0,e=0,f= 0,g=0,h=0;
            //上下方向
            for (int j = 1; j < 6; j++) {
                if (arr[x][y] == arr[x - j][y])
                    a = a + 1;
                else
                    break;
            }
            for (int k = 1; k < 6; k++) {
                if (arr[x][y] == arr[x + k][y])
                    b = b + 1;
                else
                    break;
            }
            if ((a + b) == 4) {
                if(s%2==0) {
                    System.out.print("白棋");
                }
                else
                    System.out.print("黑棋");
                System.out.println("获胜！");
                break;
            }
            //左右方向
            for (int j = 1; j < 6; j++) {
                if (arr[x][y] == arr[x ][y-j])
                    c = c + 1;
                else
                    break;
                }
            for (int k = 1; k < 6; k++) {
                if (arr[x][y] == arr[x ][y+k])
                    d = d + 1;
                else
                    break;
            }
            if ((c + d) == 4) {
                if(s%2==0) {
                    System.out.print("白棋");
                }
                else
                    System.out.print("黑棋");
                System.out.println("获胜！");
                break;
            }
            //左上到右下方向
            for (int j = 1; j < 6; j++) {
                if (arr[x][y] == arr[x-j][y-j])
                    e = e + 1;
                else
                    break;
            }
            for (int k = 1; k < 6; k++) {
                if (arr[x][y] == arr[x+k][y+k])
                    f = f + 1;
                else
                    break;
            }
            if ((e + f) == 4) {
                if(s%2==0) {
                    System.out.print("白棋");
                }
                else
                    System.out.print("黑棋");
                System.out.println("获胜！");
                break;
            }
            //右上到左下方向
            for (int j = 1; j < 6; j++) {
                if (arr[x][y] == arr[x-j][y+j])
                    g = g + 1;
                else
                    break;
            }
            for (int k = 1; k < 6; k++) {
                if (arr[x][y] == arr[x+k][y-k])
                    h = h + 1;
                else
                    break;
            }
            if ((g + h) == 4) {
                if(s%2==0) {
                    System.out.print("白棋");
                }
                else
                    System.out.print("黑棋");
                System.out.println("获胜！");
                break;
            }
        }

    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Playgame p=new Playgame();
        p.draw();
        for(int s=1;s<=(16*16);s++){
            p.notice(s);
            p.draw();
            p.judge(p.x,p.y,s);

        }
    }
}